
import Foundation
import Thrift

do {
//     let serviceURL: URL = URL(string: "http://localhost:9090")!
//     let session: URLSession = URLSession(configuration: .default)
//
//     let transport: THTTPSessionTransport = THTTPSessionTransport.Factory(session: session, url: serviceURL).newTransport()
//     //let transport = try TSocketTransport(hostname: "localhost", port: 9090)
//
//     print("Transport established")
//
//     //  var proto = TCompactProtocol(transport: transport)
//     let proto = TBinaryProtocol(on: transport)
//     //  var client = HermesClient(inoutProtocol: proto)
//     let client = TestServiceClient(inoutProtocol: proto)
//
//     let result = try client.Hello(HelloString: "Thrift!")
//     print(result)
//
//     let sampleStruct = try client.GetSampleStruct(key: 3, value: "Three")
//     print("\(sampleStruct.key) \(sampleStruct.value)")


    // Client Example
        let serviceURL: URL = URL(string: "http://localhost:9090")!
        let session: URLSession = URLSession(configuration: .default)

 //       let transport: THTTPSessionTransport = THTTPSessionTransport.Factory(session: session, url: serviceURL).newTransport()

  print("--1.---")

   let transport = try TSocketTransport(hostname: "127.0.0.1", port: 9091)
      print("--2.---")

   // try transport.open()


    // var proto = TCompactProtocol(on: transport)
   let proto = TBinaryProtocol(on: transport)
   //  var client = HermesClient(inoutProtocol: proto)
   let client = TestServiceClient(inoutProtocol: proto)
    do {
        print("--1---")
      let result = try client.Hello(HelloString: "Thrift!")

//           let sampleStruct = try client.GetSampleStruct(key: 3, value: "Three")
//           print("\(sampleStruct.key) \(sampleStruct.value)")

       print("---2--")
        print(result)
    } catch let error {
        print("\(error)")
    }
    
} catch let error {
    print("\(error)")
}
